// if (!layer) {
//     alert("请加载layer")
// }
var $ = layui.jquery;
var layer = layui.layer;
var api = {
    basePath:"",
    upPath:'',
    loading:"",
    ajax:function(requestUrl,method,requestData,SuccessCallback,successPar){
        api.loading = layer.load(5);
        $.ajax({
            type: method,
            url: api.basePath + requestUrl,
            data: requestData,
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            sync: false,
            success: function(data) {
                layer.close(api.loading);
                var obj = null;
                try {
                    obj = eval('(' + data + ')');
                } catch (ex) {
                    obj = data;
                }
                layer.close(api.loading);
                if (obj.type == "success"){
                    SuccessCallback(obj,successPar);
                }else{
                    layer.msg(obj.message,{icon:5});
                }

            },
            error: function(err) {
                layer.close(api.loading);
                console.log(err);
            },
            complete: function(XHR, TS) {
                XHR = null
            }
        });
    },
}

var tool = {
    getQueryString:function (name){
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
}

function getWidth(item,num) {
    var screen = 1200;
    var feng = num - 1;
    return (screen - item * num) / feng / 2
}

